package top.amot.forceview.theme

import android.content.Context
import android.graphics.Color
import android.graphics.Paint
import android.text.TextPaint
import android.util.SparseIntArray


class  DefaultTheme @JvmOverloads constructor(
    private val context: Context, private val linkStyle: I_LinkStyle = DefaultLinkStyle(
        context
    ), private val nodeStyle: I_NodeStyle = DefaultNodeStyle(context)
) : I_Theme {
    override val padding = 5f
    override var textBaseline = 0f
        private set
    override var textHeight = 0f
        private set
    override var linkTextBaseline = 0f
        private set
    override val linkColor: Int
        get() = linkStyle.linkColor
    override val nodeColor: Int
        get() = nodeStyle.nodeColor

    override fun getColor(level: Int): Int {
        return nodeStyle.getColor(level)
    }

    override val selectLinkColor: Int
        get() = linkStyle.selectLinkColor
    override val selectNodeColor: Int
        get() = nodeStyle.selectNodeColor
    override val paint: Paint
        get() = nodeStyle.paint
    override val linkPaint: Paint
        get() = linkStyle.linkPaint
    override val textPaint: TextPaint
        get() = nodeStyle.textPaint
    override val linkTextPaint: TextPaint
        get() = linkStyle.linkTextPaint
    override val colorArray: SparseIntArray
        get() = nodeStyle.colorArray

    override fun measureText() {
        var fontMetrics: Paint.FontMetrics = textPaint.fontMetrics
        textBaseline = (fontMetrics.bottom + fontMetrics.top) * 0.5f
        textHeight = fontMetrics.bottom - fontMetrics.top
        fontMetrics = linkTextPaint.fontMetrics
        linkTextBaseline = (fontMetrics.bottom + fontMetrics.top) * 0.5f
    }

    override val backgroundColor: Int
        get() = Color.WHITE
}